package com.example.win.android_banduyujia.peopleactivity.ui.activity;

import android.app.Activity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.win.android_banduyujia.R;

/**
 * Created by Win on 2015/8/6.
 */
public class TitleActionBarHelper  {

    private Activity  mActivity;

    private ImageView  ImageBack;
    private TextView  TxvTitle, TxvFinish;
    private ImageView ImageIcon;

    public TitleActionBarHelper(Activity activity) {
        mActivity = activity;
    }

    public void onCreate() {
        mActivity.setTheme(R.style.TitleBarName);
        mActivity.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    }

    public void initTitle() {
        mActivity.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_data);
        mActivity.getWindow().setBackgroundDrawable(null);
        getTitleBarViews();
        initTitleBar();
    }

    public void getTitleBarViews() {
        ImageBack = (ImageView) mActivity.findViewById(R.id.title_image_view_back);
        TxvTitle = (TextView) mActivity.findViewById(R.id.title_text_view_data);
        ImageIcon = (ImageView) mActivity.findViewById(R.id.title_image_icon);
        TxvFinish = (TextView) mActivity.findViewById(R.id.title_text_finish);
    }

    public void initTitleBar() {
        ImageBack.setVisibility(View.GONE);
        TxvTitle.setVisibility(View.GONE);
        ImageIcon.setVisibility(View.GONE);
        TxvFinish.setVisibility(View.GONE);
    }

    public void showBackButton(final boolean isSetResultOk) {
        ImageBack.setVisibility(View.VISIBLE);
        ImageBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isSetResultOk)
                    mActivity.setResult(Activity.RESULT_OK);
                mActivity.finish();
            }
        });
    }

    public void hideBackButton() {
        ImageBack.setVisibility(View.GONE);
    }

    public void setBigTitle(String bigTitle) {
        TxvTitle.setVisibility(View.GONE);
        TxvTitle.setText(bigTitle);
    }

    public void setBigTitleById(int bigTitle) {
         TxvTitle.setVisibility(View.VISIBLE);
         TxvTitle.setText(mActivity.getString(bigTitle));
    }

    public void setSmallTitle(int smallTitle) {
         TxvTitle.setVisibility(View.GONE);
         TxvTitle.setText(mActivity.getString(smallTitle));
    }

    public void setRightButtonTextAndListener(int textId, View.OnClickListener listener) {
          ImageIcon.setVisibility(View.GONE);
          ImageIcon.setOnClickListener(listener);
    }

    public void setRightButtonImageAndListener(int imageId, View.OnClickListener listener) {
          ImageIcon.setVisibility(View.VISIBLE);
          ImageIcon.setImageResource(imageId);
          ImageIcon.setOnClickListener(listener);
    }

    public void setRightTextViewListener(int textId, View.OnClickListener listener) {
         TxvFinish.setVisibility(View.VISIBLE);
         TxvFinish.setText(textId);
         TxvFinish.setOnClickListener(listener);
    }
}
